import { Component, OnInit, OnDestroy } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { Observable, Subject } from 'rxjs';

@Component({
    selector: 'app-not-found',
    templateUrl: './notFound.component.html',
    styleUrls: ['./notFound.component.scss']
})

export class NotFoundComponent implements OnInit, OnDestroy {
    count: Number = 5;
    destroyComponent$ = new Subject();

    constructor(
        private router: Router
    ) { }

    ngOnDestroy(): void {
        this.destroyComponent$.next();
        this.destroyComponent$.complete();
    }

    ngOnInit() {
        Observable.interval(1000)
            .take(5)
            .map(x => 4 - x)
            .do(x => this.count = x)
            .filter(x => x === 0)
            .takeUntil(this.destroyComponent$)
            .subscribe(x => {
                this.jump2Index();
            });
    }

    jump2Index() {
        this.router.navigate(['home']);
    }
}
